package loveappservice.controller;

import loveappservice.domain.Comm;
import loveappservice.service.User_service;
import loveappservice.service.impl.User_service_impl;
import loveappservice.util.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class commController {
    //实例化Service类
    User_service user_service = new User_service_impl();

    /*查询纪念日列表，也可查询一个纪念日数据*/
    @RequestMapping("/selectComm")
    public Result selectComm(String comm_id){
        if (comm_id==null){
            //获取所有纪念日
            List<Comm> comms = user_service.allComm();
            System.out.println(comms);
            return Result.success(comms);
        }else {
            /*获取一个纪念日信息*/
            Comm oneComm = user_service.findOneComm(Integer.parseInt(comm_id));
            System.out.println(oneComm);
            return Result.success(oneComm);
        }
    }
    /*新增一个纪念日*/
    @RequestMapping("/addComm")
    public Result addComm(Comm comm){
        /*新增一个纪念日*/
        int result = user_service.addComm(comm);
        System.out.println(result);
        return Result.success(result);
    }

    /*修改纪念日*/
    @RequestMapping("/upComm")
    public Result upComm(Comm comm){
        /*修改纪念日*/
        int result = user_service.amendComm(comm);
        System.out.println(result);
        return Result.success(result);
    }

    /*删除一个纪念日*/
    @RequestMapping("/deleteComm")
    public Result deleteComm(int comm_id){
        /*调用服务删除一条纪念日*/
        boolean result = user_service.deleComm(comm_id);
        System.out.println(result);
        return Result.success(result);
    }




}






